﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// GrowablePoissonDiskEffect Effect
    /// </summary>
    public class GrowablePoissonDiskEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GrowablePoissonDiskEffect), 0);
        public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.5, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(2)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(GrowablePoissonDiskEffect.InputProperty));
            }
            set
            {
                this.SetValue(GrowablePoissonDiskEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Height du Shader
        /// </summary>
        public double Height
        {
            get
            {
                return ((double)this.GetValue(GrowablePoissonDiskEffect.HeightProperty));
            }
            set
            {
                this.SetValue(GrowablePoissonDiskEffect.HeightProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Radius du Shader
        /// </summary>
        public double Radius
        {
            get
            {
                return ((double)this.GetValue(GrowablePoissonDiskEffect.RadiusProperty));
            }
            set
            {
                this.SetValue(GrowablePoissonDiskEffect.RadiusProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Width du Shader
        /// </summary>
        public double Width
        {
            get
            {
                return ((double)this.GetValue(GrowablePoissonDiskEffect.WidthProperty));
            }
            set
            {
                this.SetValue(GrowablePoissonDiskEffect.WidthProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Construteur statique
        /// </summary>
        static GrowablePoissonDiskEffect()
        {
            GrowablePoissonDiskEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/GrowablePoissonDisk.ps");
        }

        /// <summary>
        /// Construteur de la classe
        /// </summary>
        public GrowablePoissonDiskEffect()
        {
            this.PixelShader = GrowablePoissonDiskEffect._PixelShader;

            this.UpdateShaderValue(InputProperty);
            this.UpdateShaderValue(RadiusProperty);
            this.UpdateShaderValue(WidthProperty);
            this.UpdateShaderValue(HeightProperty);
        }

        #endregion
    }
}
